package com.wei.controller;


import com.wei.entity.GdComplain;
import com.wei.entity.GdRepairs;
import com.wei.mapper.GdComplainMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李泽伟
 * @since 2022-03-08
 */
@RestController
@RequestMapping
public class GdComplainController {

    @Autowired
    private GdComplainMapper complainMapper;

    @RequestMapping("/getComplain")
    public List<GdComplain> getComplain(){
        Map<String, Object> map = new HashMap<>();
        map.put("deleted", 0);
        return complainMapper.selectByMap(map);
    }

    @RequestMapping("/addComplain")
    public void setComplain(@RequestParam Map<String,Object> complainObj){
        GdComplain complain =setParam(complainObj);
        complainMapper.insert(complain);
    }

    @RequestMapping("/updateComplain")
    public void updateComplain(@RequestParam Map<String,Object> complainObj){
        GdComplain complain = setParam(complainObj);
        complainMapper.updateById(complain);
    }

    @RequestMapping("/deleteComplain")
    public void deleteComplain(@RequestParam String complainId){
        complainMapper.deleteById(complainId);
    }

    /**
     * 通过物业地址进行记录查询，用于投诉信息的管理(用户)
     * @param address
     * @return
     */
    @RequestMapping("/getComplainByAddress")
    public List<GdComplain> getComplainByAddress(@RequestParam String address){
        Map<String, Object> map = new HashMap<>();
        map.put("deleted", 0);
        map.put("property_address2", address);
        return complainMapper.selectByMap(map);
    }

    /**
     * 设置参数方法
     * @param complainObj
     * @return
     */
    private GdComplain setParam(@RequestParam Map<String, Object> complainObj) {
        GdComplain complain=new GdComplain();
        complain.setComplainId((String) complainObj.get("complainId"));
        complain.setComplainProblem((String) complainObj.get("complainProblem"));
        complain.setComplainPhone((String) complainObj.get("complainPhone"));
        complain.setComplainForeignkey1((String) complainObj.get("complainForeignkey1"));
        complain.setComplainForeignkey2((String) complainObj.get("complainForeignkey2"));
        complain.setComplainDate((String) complainObj.get("complainDate"));
        complain.setComplainSituation((String) complainObj.get("complainSituation"));
        complain.setComplainSolvedate((String) complainObj.get("complainSolvedate"));
        complain.setComplainSolvename((String) complainObj.get("complainSolvename"));
        complain.setPropertyAddress1((String) complainObj.get("propertyAddress1"));
        complain.setPropertyAddress2((String) complainObj.get("propertyAddress2"));
        return complain;
    }
}

